package org.gruposp2p.dnie.model;

/**
 *
 * @author jj
 */
public class DNIePrincipal {
	
    public String CN;
    public String SERIALNUMBER;
    public String C;

    public DNIePrincipal(String RFC1779PrincipalName) {
        int cnStartIndex = RFC1779PrincipalName.indexOf("\"");
        int cnEndIndex = RFC1779PrincipalName.indexOf("\"", cnStartIndex +1);
        CN = RFC1779PrincipalName.substring(cnStartIndex + 1, cnEndIndex);
        int cnParenthesisStartIndex = CN.indexOf("(");
        CN = CN.substring(0, cnParenthesisStartIndex).trim();
        String serialNumberSep = "OID.2.5.4.5=";
        int SERIALNUMBERStartIndex = RFC1779PrincipalName.indexOf(serialNumberSep);
        int SERIALNUMBEREndIndex =
                RFC1779PrincipalName.indexOf("," , SERIALNUMBERStartIndex + 1);
        SERIALNUMBER = RFC1779PrincipalName.substring(
                SERIALNUMBERStartIndex + serialNumberSep.length(), SERIALNUMBEREndIndex);
        String cSep ="C=";
        int CStartIndex = RFC1779PrincipalName.indexOf(cSep);
        C = RFC1779PrincipalName.substring(CStartIndex + cSep.length()).trim();
    }

    public static void main(String[] args) {
        String ppal =
                "CN=\"GARCIA ZORNOZA, JOSE JAVIER (FIRMA)\", OID.2.5.4.42=JOSE JAVIER, OID.2.5.4.4=GARCIA, OID.2.5.4.5=05555555H, C=ES";
    }
    
}
